<template>
	<view>
		<view class="goods-list">
			<view v-for='(goods,index) in goodsapp' :key='index' @click="godetail(goods)">
				<goods-item :goods="goods"></goods-item>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		goodslist
	} from '../../api/goods_list_request.js'
	export default {
		data() {
			return {
				queryObj: {
					query: '',
					cid: '',
					pagenum: 1,
					pagesize: 10
				},
				goodsapp: [],
				total: 0,
				// 节流阀
				xiang: false
			};
		},
		onLoad(options) {
			console.log(options);
			this.queryObj.query = options.query || '';
			this.queryObj.cid = options.cid || '';
			this.getgoods();
		},
		methods: {
			async getgoods(callback) {
				this.xiang = true
				callback && callback();
				const {
					data: res
				} = await goodslist(this.queryObj);
				this.xiang = false
				console.log(res)
				if (res.meta.status !== 200) return uni.$showMsg();
				this.goodsapp = [...this.goodsapp, ...res.message.goods];
				this.total = res.message.total;
			},
			// 跳转商品详情
			godetail(goods) {
				uni.navigateTo({
					url: '/ok/goods_detail/goods_detail?goods_id=' + goods.goods_id
				})
			}

		},

		onReachBottom() {
			console.log(111);
			if (this.queryObj.pagenum * this.queryObj.pagesize >= this.total) return uni.$showMsg('数据加载完成！')
			if (this.xiang) return;
			this.queryObj.pagenum += 1;
			this.getgoods();
		},
		onPullDownRefresh() {
			console.log(22);
			this.queryObj.pagenum = 1;
			this.total = 0;
			this.goodsapp = [];
			this.getgoods(() => uni.stopPullDownRefresh());
		},

	}
</script>

<style lang="less">
	.goods-list {}
</style>
